<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 布局 -->
      <el-row>
        <el-col :span="9">
          <!-- 搜索框 -->
          <el-input placeholder="请输入内容" v-model="queryInfo.query">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table :data="orderData" style="width: 100%" border stripe>
        <el-table-column type="index" label="#">
        </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="90">
        </el-table-column>
        <el-table-column label="是否付款" width="90">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发送" width="90">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="200">
          <template slot-scope="scope">
            {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column>
        <!-- 操作按钮 -->
        <el-table-column label="操作" width="170">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="revFormData(scope.row)"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressData"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
      @size-change="pageSizeChange"
      @current-change="pageNumChange"
      :current-page="queryInfo.pagenum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
    title="修改地址"
    :visible.sync="revDialogVisible"
    width="50%" @closed="revFormClosed">
      <!-- 修改表单 -->
      <el-form :model="revForm" :rules="revRules" ref="revFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="address">
          <el-cascader expand-trigger="hover" :options="citydata"
          v-model="revForm.address" @change="handleChange" style="width: 100%">
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="revForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="revDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="revDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog
    title="物流进度" :visible.sync="progressVisible" width="50%">
      <el-timeline>
        <el-timeline-item
        v-for="(item, i) in progressInfo"
        :key="i"
        :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
     </el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
import progressInfo from './progressInfo'

export default {
  data() {
    return {
      // 首次获取数据的请求体
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: '',
      // 订单数据列表
      orderData: [],
      // 控制修改地址对话框的显示与隐藏
      revDialogVisible: false,
      // 修改表单绑定的数据
      revForm: {
        address: [],
        address2: ''
      },
      // 校验规则
      revRules: {
        address: [{ required: true, message: '请选择省市/县', trigger: 'blur' }],
        address2: [{ required: true, message: '请输入详细地址', trigger: 'blur' }]
      },
      // 级联选择框绑定的数据
      citydata,
      // 物流进度对话框的显示与隐藏
      progressVisible: false,
      // 物流进度数据
      progressInfo
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    // 订单列表数据获取
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', { params: this.queryInfo })
      console.log(res.data)
      if (res.meta.status !== 200) return this.$message.error('获取订单列表数据失败')
      this.orderData = res.data.goods
      this.total = res.data.total
    },
    // 监听分页区域每页显示条数切换(尺寸变化)
    pageSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrderList()
    },
    // 监听当前页变化事件
    pageNumChange(newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrderList()
    },
    // 监听操作编辑按钮
    revFormData(row) {
      this.revDialogVisible = true
      console.log(row)
    },
    // 监听表单关闭事件
    revFormClosed() {
      this.$refs.revFormRef.resetFields()
    },
    // 监听操作地址按钮
    async showProgressData() {
    //   const { data: res } = await this.$http.get('/kuaidi/1106975712662')
    //   if (res.meta.status !== 200) return this.$message.error('获取物流进度失败')
    //   this.progressInfo = res.data
    //   console.log(this.progressInfo)
      this.progressVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
@import '../../plugins/timeline/timeline.css';
@import '../../plugins/timeline-item/timeline-item.css';
</style>
